package com.edu.his.service.impl;

import com.edu.his.domain.Prescription;
import com.edu.his.domain.Register;
import com.edu.his.mapper.PrescriptionMapper;
import com.edu.his.mapper.RegisterMapper;
import com.edu.his.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.edu.his.mapper.DrugInfoMapper;
import com.edu.his.service.DrugInfoService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 描述：
 * 创建人：飘
 * 创建时间：2024/12/16
 **/
@Service
public class DrugInfoServiceImpl implements DrugInfoService{

    @Autowired
    private DrugInfoMapper drugInfoMapper;
    @Autowired
    private PrescriptionMapper prescriptionMapper;
    @Autowired
    private RegisterMapper registerMapper;

    @Override
    public R selectByRegisterId(Integer registerId) {
        return R.success(200,"查询成功",this.drugInfoMapper.selectByRegisterId(registerId));
    }

    @Transactional
    @Override
    public R updateState(Prescription prescription) {

        //2>修改挂号状态 3（本次看诊状态（1-已挂号2-医生接诊3-看诊结束4-已退号）

        Register register=new Register();
        register.setVisitState(3);
        register.setId(prescription.getRegisterId());
        this.registerMapper.updateState(register);
        //修改发药状态
        this.prescriptionMapper.updateState(prescription);

        return R.success(200,"修改状态成功",1);
    }
}
